package com.yy.weixinpay.controller;

import com.yy.weixinpay.entity.OrderInfo;
import com.yy.weixinpay.enums.OrderStatus;
import com.yy.weixinpay.service.OrderInfoService;
import com.yy.weixinpay.vo.R;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/order-info")
@CrossOrigin
@Api(tags = "订单管理")
public class OrderInfoController {
    @Autowired
    private OrderInfoService orderInfoService;

    //展示订单信息
    @GetMapping("/list")
    public R list(){
        List<OrderInfo> list = orderInfoService.listOrderByCreateTimeDesc();
        return R.ok().data("list",list);
    }

    //查询本地支付订单
    @GetMapping("/query-order-status/{orderNo}")
    public R queryOrderStatus(@PathVariable String orderNo){
        String orderStatus = orderInfoService.getOrderStatus(orderNo);
        if (OrderStatus.SUCCESS.getType().equals(orderStatus)){
            return R.ok().setMessage("支付成功");
        }
        return R.ok().setCode(100).setMessage("支付中......");
    }
}
